home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 001 / wwiv.arc / DLOADS.PAS < prev    next >
Pascal/Delphi Source File  |  1986-04-06  |  26KB  |  983 lines

  1. Program dloads;
  2.  
  3.                       {*****************************}
  4.                       {Copyright (c) 1986 Wayne Bell}
  5.                       {*****************************}
  6.  
  7. {$V-} {$C-}
  8. {$I COMMON.PAS}
  9.  
  10. var ulf:file of ulrec;
  11.     uboards:array[0..19] of ulrec;
  12.     ulff:file of ulfrec;
  13.     crc,culb,maxulb:integer;
  14.     sortbd,doneft:boolean;
  15.     ldat:str;
  16.     ymodem,ucrc,bnp:boolean;
  17.     chksum:byte;
  18.     lrn:integer;
  19.     lfn:str;
  20.     ft:byte;
  21.  
  22.  
  23. procedure printfile(fn:str);
  24. var fil:text;
  25.     i:str;
  26.     abort,next:boolean;
  27. begin
  28.  if not hangup then begin
  29.   assign(fil,fn);
  30.   {$I-} reset(fil); {$I+}
  31.   if ioresult<>0 then print('File not found.') else begin
  32.     abort:=false;
  33.     while not eof(fil) and (not abort) and (not hangup) do begin
  34.       readln(fil,i);
  35.       if i[length(i)]<>#1 then i:=i+#1;
  36.       printa(i,abort,next);
  37.     end;
  38.     close(fil);
  39.   end;
  40.   nl;nl;
  41.  end;
  42. end;
  43.  
  44. function tcheck(s:real; i:integer):boolean;
  45. var r:real;
  46. begin
  47.   r:=timer;
  48.   if r<s then r:=r+86400.0;
  49.   if trunc(r-s)>i then tcheck:=false else tcheck:=true;
  50. end;
  51.  
  52. function tchk(s:real; i:real):boolean;
  53. var r:real;
  54. begin
  55.   r:=timer;
  56.   if r<s then r:=r+86400.0;
  57.   if (r-s)>i then tchk:=false else tchk:=true;
  58. end;
  59.  
  60. {$I DLP1.PAS}
  61.  
  62. procedure i1;
  63. begin
  64.   assign(ulf,'gfiles\uploads.dat');
  65.   reset(ulf); maxulb:=-1;
  66.   while not eof(ulf) do begin maxulb:=maxulb+1; read(ulf,uboards[maxulb]); end;
  67.   close(ulf);
  68.   culb:=1;
  69.   ldat:=thisuser.laston;
  70. end;
  71.  
  72. function exist(fn:str):boolean;
  73. var f:file;
  74. begin
  75.   assign(f,fn);
  76.   {$I-} reset(f); {$I+}
  77.   if ioresult=0 then begin close(f); exist:=true end else exist:=false;
  78. end;
  79.  
  80. function align(fn:str):str;
  81. var f,e,t:str; c,c1:integer;
  82. begin
  83.   c:=pos('.',fn);
  84.   if c=0 then begin
  85.     f:=fn; e:='   ';
  86.   end else begin
  87.     f:=copy(fn,1,c-1); e:=copy(fn,c+1,3);
  88.   end;
  89.   while length(f)<8 do f:=f+' ';
  90.   while length(e)<3 do e:=e+' ';
  91.   if length(f)>8 then f:=copy(f,1,8);
  92.   if length(e)>3 then e:=copy(e,1,3);
  93.   c:=pos('*',f); if c<>0 then for c1:=c to 8 do f[c1]:='?';
  94.   c:=pos('*',e); if c<>0 then for c1:=c to 3 do e[c1]:='?';
  95.   c:=pos(' ',f); if c<>0 then for c1:=c to 8 do f[c1]:=' ';
  96.   c:=pos(' ',e); if c<>0 then for c1:=c to 3 do e[c1]:=' ';
  97.   align:=f+'.'+e;
  98. end;
  99.  
  100. function fit(f1,f2:str):boolean;
  101. var tf:boolean; c:integer;
  102. begin
  103.   tf:=true;
  104.   for c:=1 to 12 do
  105.     if (f1[c]<>f2[c]) and (f1[c]<>'?') then tf:=false;
  106.   fit:=tf;
  107. end;
  108.  
  109. procedure iscan(var pl:integer);
  110. var f:ulfrec;
  111. begin
  112.   assign(ulff,'gfiles\'+uboards[culb].filename);
  113.   {$I-} reset(ulff); {$I+}
  114.   if ioresult<>0 then begin
  115.     rewrite(ulff);
  116.     f.blocks:=0;
  117.     write(ulff,f);
  118.   end;
  119.   seek(ulff,0);
  120.   read(ulff,f);
  121.   pl:=f.blocks;
  122.   bnp:=false;
  123. end;
  124.  
  125. procedure recno(fn:str; var pl,rn:integer);
  126. var c:integer;
  127.     f:ulfrec;
  128. begin
  129.   fn:=align(fn);
  130.   iscan(pl); rn:=0; c:=1;
  131.   while (c<=pl) and (rn=0) do begin
  132.     seek(ulff,c); read(ulff,f);
  133.     if fit(fn,align(f.filename)) then rn:=c;
  134.     c:=c+1;
  135.   end;
  136.   lrn:=rn;
  137.   lfn:=fn;
  138. end;
  139.  
  140. procedure nrecno(fn:str; var pl,rn:integer);
  141. var c:integer;
  142.     f:ulfrec;
  143. begin
  144.   fn:=align(fn);
  145.   if fn=lfn then begin
  146.     if (lrn<pl) and (lrn>0) then begin
  147.       c:=lrn+1; rn:=0;
  148.       while (c<=pl) and (rn=0) do begin
  149.         seek(ulff,c); read(ulff,f);
  150.         if fit(fn,align(f.filename)) then rn:=c;
  151.         c:=c+1;
  152.       end;
  153.       lrn:=rn;
  154.     end else rn:=0;
  155.   end else rn:=0;
  156. end;
  157.  
  158. procedure arcl(fn:str; var abort:boolean);
  159. type ei=record l,h:integer; end;
  160.      archead=record
  161.                name:array[1..13] of char;
  162.                size:ei;
  163.                date,time,crc:integer;
  164.                len:ei;
  165.              end;
  166. var f:file; b:byte;
  167.     head:archead;
  168.     done,next:boolean;
  169.  
  170.   function valueei(x:ei):real;
  171.   var r:real; tf:boolean;
  172.   begin
  173.     if x.h>=0 then begin r:=int(x.h)*65536.0; tf:=true; end else
  174.       begin tf:=false; if x.h=$8000 then r:=65536.0*65536.0 else
  175.         r:=int(-x.h)*65536.0; end;
  176.     if x.l>=0 then r:=r+int(x.l)
  177.     else if x.l=$8000 then r:=r+32760.0
  178.     else r:=r+65536.0+x.l;
  179.     if tf then valueei:=r else valueei:=-r;
  180.   end;
  181.  
  182.   procedure pfn;
  183.   var i,i1:str; try:byte;
  184.   begin
  185.     b:=0; try:=0;
  186.     while not eof(f) and (b<>26) and (try<5) do begin
  187.       blockread(f,b,1);
  188.       try:=try+1;
  189.     end;
  190.     if try>=5 then longseek(f,filesize(f)-2.0);
  191.     if longfilepos(f)+27<longfilesize(f) then begin
  192.       blockread(f,b,1);
  193.       if b<>0 then begin
  194.           if b=1 then begin
  195.           blockread(f,head,sizeof(head)-sizeof(ei));
  196.           head.len:=head.size;
  197.         end else blockread(f,head,sizeof(head));
  198.         i:=''; b:=1;
  199.         while (head.name[b]<>#0) and (b<=13) do begin
  200.           i:=i+head.name[b];
  201.           b:=b+1;
  202.         end;
  203.         i:=align(i)+' ';
  204.         i1:=cstrr(valueei(head.len));
  205.         while length(i1)<7 do i1:=' '+i1;
  206.         i:=i+i1;
  207.         printacr(i,abort,next);
  208.       end else done:=true;
  209.       longseek(f,longfilepos(f)+valueei(head.size));
  210.     end;
  211.   end;
  212.  
  213. begin
  214.   assign(f,fn);
  215.   reset(f,1); done:=false;
  216.   while (longfilepos(f)+27.0<longfilesize(f)) and not (abort or done) do
  217.     pfn;
  218.   close(f);
  219. end;
  220.  
  221. procedure lbrl(fn:str; var abort:boolean);
  222. var f:file;
  223.     c,n,n1:integer;
  224.     x:record
  225.         st:byte;
  226.         name:array[1..8] of char;
  227.         ext:array[1..3] of char;
  228.         index,len:integer;
  229.         fil:array[1..16] of byte;
  230.       end;
  231.     next:boolean;
  232.     i,i1:str;
  233.  
  234. begin
  235.   assign(f,fn);
  236.   reset(f,32);
  237.   blockread(f,x,1);
  238.   c:=x.len*4-1;
  239.   for n:=1 to c do begin
  240.     blockread(f,x,1); i:='';
  241.     if (x.st=0) and not abort then begin
  242.       for n1:=1 to 8 do i:=i+x.name[n1];
  243.       i:=i+'.';
  244.       for n1:=1 to 3 do i:=i+x.ext[n1];
  245.       i:=align(i)+' ';
  246.       i1:=cstrr(x.len*128.0);
  247.       while length(i1)<7 do i1:=' '+i1;
  248.       i:=i+i1;
  249.       printacr(i,abort,next);
  250.     end;
  251.   end;
  252.   close(f);
  253. end;
  254.  
  255. procedure lfi(fn:str; var abort:boolean);
  256. var next:boolean; i1,i2:str;
  257. begin
  258.   if exist('dloads\'+fn) and (not abort) then
  259.     if (pos('.ARC',fn)<>0) or (pos('.LBR',fn)<>0) then begin
  260.       nl;
  261.       i1:=align(fn); i2:=''; while length(i1)>length(i2) do i2:=i2+'-';
  262.       printacr(i1,abort,next);
  263.       printacr(i2,abort,next);
  264.       nl;
  265.       if not abort then begin
  266.         if pos('.ARC',fn)<>0 then arcl('dloads\'+fn,abort);
  267.         if pos('.LBR',fn)<>0 then lbrl('dloads\'+fn,abort);
  268.       end;
  269.       nl;
  270.     end;
  271. end;
  272.  
  273. procedure lfin(rn:integer; var abort:boolean);
  274. var f:ulfrec;
  275. begin
  276.   seek(ulff,rn); read(ulff,f); lfi(f.filename,abort);
  277. end;
  278.  
  279. procedure lfii;
  280. var fn:str; pl,rn:integer; abort:boolean;
  281. begin
  282.   helpl:='[';
  283.   nl; print('Enter file to list interior files of');
  284.   prompt(': '); input(fn,12);
  285.   recno(fn,pl,rn);
  286.   abort:=false;
  287.   if rn=0 then print('File not found.') else begin
  288.     while (rn<>0) and (not abort) do begin
  289.       lfin(rn,abort);
  290.       nrecno(fn,pl,rn);
  291.     end;
  292.   end;
  293.   close(ulff);
  294. end;
  295.  
  296. procedure return;
  297. var f:file;
  298. begin
  299.   assign(f,'bbs.com');
  300.   print('Returning to BBS...');
  301.   remove_port;
  302.   if hangup then term_ready(false);
  303.   execute(f);
  304. end;
  305.  
  306.  
  307. procedure pbn(var abort:boolean);
  308. var i,i1:str; next:boolean;
  309. begin
  310.   if not bnp then begin
  311.     nl;
  312.     i:=uboards[culb].name+' #'+cstr(culb);
  313.     i1:='---'; while length(i1)<length(i) do i1:=i1+'-';
  314.     nl; nl;
  315.     printacr(i,abort,next);
  316.     printacr(i1,abort,next);
  317.     nl;
  318.   end;
  319.   bnp:=true;
  320. end;
  321.  
  322.  
  323. function uc(s:str):str;
  324. var x:str; i:integer;
  325. begin
  326.   x:=s;
  327.   for i:=1 to length(s) do
  328.     x[i]:=upcase(x[i]);
  329.   uc:=x;
  330. end;
  331.  
  332. procedure dlx(f1:ulfrec; var abort:boolean);
  333. var inte,pl,c:integer; ok,tl:boolean; u:userrec; rl:real; i,ii:str;
  334. begin
  335.     nl; nl;
  336.     print('Filename: "'+align(f1.filename)+'"');
  337.     print('Desc.   : '+f1.description);
  338.     print('# blocks: '+cstr(f1.blocks)+'-'+cstr((f1.blocks+7)div 8));
  339.     inte:=value(spd); if inte=0 then inte:=1200;
  340.     rl:=1620.0*f1.blocks/inte;
  341.     if rl>32767.0 then rl:=32000; if rl<0.0 then rl:=0;
  342.     inte:=trunc(rl);
  343.     i:=cstr(inte div 3600)+':'; ii:=cstr((inte mod 3600) div 60);
  344.     if length(ii)=1 then ii:='0'+ii; i:=i+ii+':';
  345.     ii:=cstr(inte mod 60); if length(ii)=1 then ii:='0'+ii;
  346.     i:=i+ii; print('apx time: '+i);
  347.     reset(uf); seek(uf,f1.owner); read(uf,u); close(uf);
  348.     print('U/L by  : '+u.name+' #'+cstr(f1.owner));
  349.     print('U/L on  : '+f1.date);
  350.     ft:=255; if (f1.ft[1]=$81) and (f1.ft[2]=$f5) then ft:=f1.ft[3];
  351.     if ft<>255 then print('File typ: '+cstr(ft));
  352.     if timer<timeon then timeon:=timeon-24.0*60*60;
  353.     tl:=((seclev[thisuser.sl].ttime*60+extratime+timeon-timer-rl)>0);
  354.     if tl or (copy(f1.filename,1,4)='WWIV') then begin
  355.       if exist('dloads\'+f1.filename) then
  356.         send1('dloads\'+f1.filename,ok,abort)
  357.       else print('File isn''t really there!');
  358.     end else print('Not enough time left to D/L');
  359. end;
  360.  
  361. procedure dl(fn:str);
  362. var pl,rn:integer; f:ulfrec; abort:boolean;
  363. begin
  364.   recno(fn,pl,rn); abort:=false;
  365.   if rn=0 then print('File not found.') else begin
  366.     while (rn<>0) and (not abort) do begin
  367.       seek(ulff,rn); read(ulff,f); dlx(f,abort);
  368.       nrecno(fn,pl,rn);
  369.     end;
  370.   end;
  371.   close(ulff);
  372. end;
  373.  
  374. procedure dl1(n:integer);
  375. var f1:ulfrec; abort:boolean;
  376. begin
  377.   nl; nl;
  378.   seek(ulff,n); read(ulff,f1);
  379.   dlx(f1,abort);
  380.   nl;
  381. end;
  382.  
  383.  
  384. procedure ul(fn:str);
  385. var x,pl,c,cc,ob,np:integer; f,f1:ulfrec; uls,ok:boolean; fi:file of byte;
  386. begin
  387.  if freek>80 then begin
  388.   uls:=incom;
  389.   ob:=culb;
  390.   ok:=true; fn:=align(fn);
  391.   if (fn[1]=' ') or (fn[10]=' ') then ok:=false;
  392.   for x:=1 to length(fn) do
  393.     if not (fn[x] in ['0'..'9','A'..'Z','.',' ']) then ok:=false;
  394.   np:=0; for x:=1 to length(fn) do if fn[x]='.' then np:=np+1;
  395.   if np<>1 then ok:=false;
  396.   if ok then
  397.     if incom then
  398.       if exist('dloads\'+fn) then
  399.         if cs then begin
  400.           print('There already is one.');
  401.           prompt('Do it anyways? ');
  402.           ok:=yn;
  403.           uls:=false;
  404.         end else
  405.           ok:=false
  406.       else
  407.         ok:=true
  408.     else
  409.       ok:=exist('dloads\'+fn)
  410.   else print('Illegal filename.');
  411.   if (not incom) then
  412.     if ok then print('Am using the file in dloads\')
  413.     else begin print('To put in a file from keyboard, it must already be');
  414.                print('present in the dloads\ directory.'); end;
  415.   nl; nl;
  416.   if ok and incom and uls then begin
  417.     assign(fi,'dloads\'+fn); {$I-} rewrite(fi); {$I+}
  418.     if ioresult<>0 then begin
  419.       {$I-} close(fi); {$I+} cc:=ioresult;
  420.       ok:=false;
  421.     end else begin close(fi); erase(fi); end;
  422.   end;
  423.   if not ok then print('Can''t use that filename, sorry.') else begin
  424.     iscan(pl);
  425.     if pl>=uboards[culb].maxfiles then print('This board is full.') else begin
  426.       prompt('Upload "'+fn+'" ? ');
  427.       if yn then begin ok:=true; close(ulff);
  428.         nl; print('Please enter a one line description.'); prompt(':');
  429.         inputl(f.description,60);
  430.         if (f.description[1]='\') or (rvalidate in thisuser.ac) then culb:=0;
  431.         if f.description[1]='\' then f.description:=copy(f.description,2,80);
  432.         iscan(pl);
  433.         ok:=true; ft:=255;
  434.         if uls then receive1('dloads\'+fn,ok);
  435.         nl; nl;
  436.         if not ok then print('Not saved.') else begin
  437.           f.filename:=fn;
  438.           f.owner:=usernum;
  439.           f.date:=date;
  440.           f.daten:=daynum(date);
  441.           for x:=1 to 17 do f.res[x]:=0;
  442.           for x:=1 to 3 do f.ft[x]:=0;
  443.           if ft<>255 then begin
  444.             f.ft[1]:=$81; f.ft[2]:=$f5; f.ft[3]:=ft;
  445.           end;
  446.           assign(fi,'dloads\'+fn);
  447.           {$I-} reset(fi); {$I+}
  448.           if ioresult=0 then begin
  449.             f.blocks:=trunc((longfilesize(fi)+127.0)/128.0);
  450.             close(fi);
  451.             for x:=pl downto 1 do begin
  452.               seek(ulff,x); read(ulff,f1);
  453.               seek(ulff,x+1); write(ulff,f1);
  454.             end;
  455.             seek(ulff,1);
  456.             write(ulff,f);
  457.             seek(ulff,0); read(ulff,f); f.blocks:=pl+1;
  458.             seek(ulff,0); write(ulff,f);
  459.             sysoplog('Uploaded "'+fn+'" on '+uboards[culb].name);
  460.             print('File successfully uploaded.');
  461.           end else begin
  462.             print('Oops, system error.  Not saved.');
  463.             sysoplog('Error uploading "'+fn+'"');
  464.           end;
  465.         end;
  466.       end;
  467.     end;
  468.     close(ulff); culb:=ob;
  469.   end;
  470.   nl; nl;
  471.   end else begin
  472.     nl; nl; print('Sorry, not enough disk space.');
  473.     nl;
  474.   end;
  475. end;
  476.  
  477. procedure idl;
  478. var i:str;
  479. begin
  480.   helpl:='X';
  481.   nl; print('Download -'); nl; prompt('Enter filename: '); input(i,12);
  482.   dl(i);
  483.   nl; nl;
  484. end;
  485.  
  486. procedure iul;
  487. var i:str;
  488. begin
  489.   helpl:='U';
  490.   nl; nl; print('Upload -'); nl; prompt('Enter filename: '); input(i,12);
  491.   ul(i);
  492.   nl; nl;
  493. end;
  494.  
  495. procedure gfn(var fn:str);
  496. begin
  497.   nl; helpl:='L';
  498.   prompt('File mask: '); input(fn,12);
  499.   if fn='' then fn:='*.*';
  500.   fn:=align(fn);
  501. end;
  502.  
  503. function aln(i:str; n:integer):str;
  504. begin
  505.   while length(i)<n do i:=' '+i;
  506.   aln:=i;
  507. end;
  508.  
  509. procedure pfn(f:ulfrec; var abort,next:boolean);
  510. begin
  511.   printacr(align(f.filename)+':'+aln(cstr(f.blocks),4)+' :'+f.description,abort,next);
  512. end;
  513.  
  514. procedure searchb(b:integer; fn:str; var abort:boolean);
  515. var oldboard,pl,rn:integer; f:ulfrec;
  516. begin
  517.   oldboard:=culb; culb:=b;
  518.   recno(fn,pl,rn);
  519.   while (rn<=pl) and (not abort) and (not hangup) and (rn<>0) do begin
  520.     seek(ulff,rn); read(ulff,f);
  521.     pbn(abort);
  522.     pfn(f,abort,next);
  523.     nrecno(fn,pl,rn);
  524.   end;
  525.   close(ulff);
  526.   culb:=oldboard;
  527. end;
  528.  
  529. procedure searchbd(b:integer; ts:str; var abort:boolean);
  530. var oldboard,pl,rn:integer; f:ulfrec; next:boolean;
  531. begin
  532.   oldboard:=culb; culb:=b; iscan(pl);
  533.   rn:=1;
  534.   while (rn<=pl) and (not abort) and (not hangup) do begin
  535.     seek(ulff,rn); read(ulff,f);
  536.     if pos(ts,uc(f.description))<>0 then begin
  537.       pbn(abort);
  538.       pfn(f,abort,next);
  539.     end;
  540.     rn:=rn+1;
  541.   end;
  542.   close(ulff);
  543.   culb:=oldboard;
  544. end;
  545.  
  546. procedure search;
  547. var fn:str; bn:integer; abort:boolean;
  548. begin
  549.   nl; nl; print('Search all directories.');
  550.   gfn(fn);
  551.   if cs then bn:=0 else bn:=1; abort:=false;
  552.   while (not abort) and (bn<=maxulb) and (not hangup) do begin
  553.     if uboards[bn].dsl<=thisuser.dsl then searchb(bn,fn,abort);
  554.     bn:=bn+1;
  555.   end;
  556. end;
  557.  
  558. procedure searchd;
  559. var fn:str; bn:integer; abort:boolean;
  560. begin
  561.   nl; nl; print('Find a description -'); nl;
  562.   print('Enter what to search description for.');
  563.   helpl:='Y';
  564.   prompt(': '); input(fn,20);
  565.   if fn<>'' then begin
  566.     nl; print('Searching for "'+fn+'"'); nl;
  567.     prompt('Search all directories? ');
  568.     if yn then begin
  569.       if cs then bn:=0 else bn:=1; abort:=false;
  570.       while (not abort) and (bn<=maxulb) and (not hangup) do begin
  571.         if uboards[bn].dsl<=thisuser.dsl then searchbd(bn,fn,abort);
  572.         bn:=bn+1;
  573.       end;
  574.     end else searchbd(culb,fn,abort);
  575.   end;
  576. end;
  577.  
  578. procedure newfiles(b:integer; var abort:boolean);
  579. var oldboard,pl,rn,ldn:integer; f:ulfrec; next:boolean;
  580. begin
  581.   oldboard:=culb; culb:=b; iscan(pl);
  582.   ldn:=daynum(ldat);
  583.   rn:=1;
  584.   while (rn<=pl) and (not abort) and (not hangup) do begin
  585.     seek(ulff,rn); read(ulff,f);
  586.     if f.daten>=ldn then begin
  587.       pbn(abort);
  588.       pfn(f,abort,next);
  589.     end;
  590.     rn:=rn+1;
  591.   end;
  592.   close(ulff);
  593.   culb:=oldboard;
  594. end;
  595.  
  596. procedure nf;
  597. var bn:integer; abort:boolean;
  598. begin
  599.   nl; print('Search for new files.'); nl;
  600.   prompt('Search all directories? ');
  601.   if yn then begin
  602.     if cs then bn:=0 else bn:=1; abort:=false;
  603.     while (not abort) and (bn<=maxulb) and (not hangup) do begin
  604.       if uboards[bn].dsl<=thisuser.dsl then newfiles(bn,abort);
  605.       bn:=bn+1;
  606.     end;
  607.   end else newfiles(culb,abort);
  608. end;
  609.  
  610. procedure delete(rn:integer; var pl:integer);
  611. var f:ulfrec; i:integer;
  612. begin
  613.   if (rn<=pl) and (rn>0) then begin
  614.     pl:=pl-1;
  615.     for i:=rn to pl do begin
  616.       seek(ulff,i+1); read(ulff,f);
  617.       seek(ulff,i); write(ulff,f);
  618.     end;
  619.     seek(ulff,0); f.blocks:=pl; write(ulff,f);
  620.   end;
  621. end;
  622.  
  623. procedure remove;
  624. var pl,c,rn:integer; f:ulfrec; fn:str; ff:file; u:userrec; tf:boolean;
  625. begin
  626.   print('Enter filename to remove.'); prompt(': ');
  627.   input(fn,12);
  628.   if fn<>'' then begin
  629.     recno(fn,pl,rn);
  630.     if rn<>0 then begin
  631.       seek(ulff,rn); read(ulff,f);
  632.       if (usernum=f.owner) or cs then begin
  633.         print('Filename: "'+f.filename+'"');
  634.         print('Desc.   : '+f.description);
  635.         print('# blocks: '+cstr(f.blocks));
  636.         reset(uf); seek(uf,f.owner); read(uf,u); close(uf);
  637.         print('U/L by  : '+u.name+' #'+cstr(f.owner));
  638.         print('U/L on  : '+f.date);
  639.         prompt('Delete this? ');
  640.         if yn then begin
  641.           delete(rn,pl);
  642.           if cs then begin
  643.             prompt('Erase file too? ');
  644.             tf:=yn;
  645.           end else tf:=true;
  646.           if tf then begin
  647.             assign(ff,'dloads\'+fn);
  648.             {$I-} erase(ff); {$I+}
  649.             c:=ioresult;
  650.           end;
  651.         end;
  652.       end;
  653.     end;
  654.     close(ulff);
  655.   end;
  656.   nl; nl;
  657. end;
  658.  
  659. procedure move;
  660. var x,pl,c,rn,int,dbn:integer; f,f1:ulfrec; fn:str; ff:file; i:str;
  661.     abort,next:boolean;
  662. begin
  663.   print('Enter filename to move.'); prompt(': ');
  664.   input(fn,12);
  665.   if fn<>'' then begin
  666.     recno(fn,pl,rn);
  667.     if rn<>0 then begin
  668.       seek(ulff,rn); read(ulff,f);
  669.       abort:=false; nl; pfn(f,abort,next); nl; nl;
  670.       prompt('Move this? ');
  671.       if yn then begin
  672.         nl;
  673.         for int:=0 to maxulb do
  674.           print(cstr(int)+' : '+uboards[int].name);
  675.         nl; nl;
  676.         prompt('To which directory? '); input(i,3);
  677.         dbn:=value(i); if (dbn=0) and (i<>'0') then dbn:=-1;
  678.         if (dbn<0) or (dbn>maxulb) then print('Can''t move it there.')
  679.         else begin
  680.           delete(rn,pl);
  681.           close(ulff);
  682.           int:=culb; culb:=dbn; iscan(pl);
  683.           for x:=pl downto 1 do begin
  684.             seek(ulff,x); read(ulff,f1);
  685.             seek(ulff,x+1); write(ulff,f1);
  686.           end;
  687.           seek(ulff,1);
  688.           write(ulff,f);
  689.           f.blocks:=pl+1;
  690.           seek(ulff,0); write(ulff,f);
  691.           culb:=int;
  692.         end;
  693.       end;
  694.     end;
  695.     close(ulff);
  696.   end;
  697. end;
  698.  
  699. procedure ren;
  700. var pl,c,rn,int,dbn:integer; f:ulfrec; fn,fd:str; ff:file; i:str;
  701. begin
  702.   print('Enter filename to rename.'); prompt(': ');
  703.   input(fn,12); nl; nl;
  704.   if fn<>'' then begin
  705.     recno(fn,pl,rn);
  706.     if rn<>0 then begin
  707.       seek(ulff,rn); read(ulff,f);
  708.       print(align(f.filename)+' : '+f.description); nl; nl;
  709.       prompt('Rename this stuff? ');
  710.       if yn then begin
  711.         prompt('New filename? '); input(fn,12);
  712.         if fn<>'' then begin
  713.           if exist('dloads\'+fn) then print('Can''t use that filename.') else begin
  714.             chdir('dloads'); assign(ff,f.filename); rename(ff,fn); chdir('..');
  715.             f.filename:=fn;
  716.           end;
  717.         end;
  718.         print('New description -'); prompt(': '); inputl(fd,60);
  719.         if fd<>'' then f.description:=fd;
  720.         seek(ulff,rn); write(ulff,f);
  721.       end;
  722.     end;
  723.     close(ulff);
  724.   end;
  725. end;
  726.  
  727. function gtr(f,f1:ulfrec):boolean;
  728. begin
  729.   if sortbd and (f1.daten<>f.daten) then
  730.     if f1.daten<f.daten then
  731.       gtr:=false
  732.     else
  733.       gtr:=true
  734.   else
  735.     if f1.filename>f.filename then
  736.       gtr:=false
  737.     else
  738.       gtr:=true;
  739. end;
  740.  
  741. procedure sortd(c:integer);
  742. var oldboard,trn,srn,i,i1,pl:integer; f,f1:ulfrec;
  743. begin
  744.   oldboard:=culb; culb:=c; iscan(pl);
  745.   nl; print('Sorting '+uboards[culb].name);
  746.   for i:=1 to pl-1 do begin
  747.     seek(ulff,i); read(ulff,f); trn:=i;
  748.     for i1:=i+1 to pl do begin
  749.       seek(ulff,i1); read(ulff,f1);
  750.       if gtr(f,f1) then begin
  751.         f:=f1; trn:=i1;
  752.       end;
  753.     end;
  754.     seek(ulff,i); read(ulff,f1); seek(ulff,i);
  755.     write(ulff,f); seek(ulff,trn); write(ulff,f1);
  756.   end;
  757.   close(ulff);
  758.   culb:=oldboard;
  759. end;
  760.  
  761. procedure sort;
  762. var bn:integer;
  763. begin
  764.   nl; nl; prompt('Sort by date? '); if yn then sortbd:=true else sortbd:=false;
  765.   nl; prompt('Sort all boards? ');
  766.   if yn then
  767.     for bn:=0 to maxulb do
  768.       sortd(bn)
  769.   else
  770.     sortd(culb);
  771. end;
  772.  
  773. procedure listfiles;
  774. var abort:boolean; fn:str;
  775. begin
  776.   nl; nl; print('List files.');
  777.   gfn(fn); abort:=false;
  778.   searchb(culb,fn,abort);
  779. end;
  780.  
  781. procedure listf(n:integer; var abort:boolean);
  782. var f:ulfrec; i,i1:str; next:boolean;
  783. begin
  784.   seek(ulff,n); read(ulff,f);
  785.   i:=cstr(n); while length(i)<3 do i:=' '+i;
  786.   i:=i+': '+align(f.filename);
  787.   while length(i)<20 do i:=i+' ';
  788.   i1:=cstr(f.blocks); while length(i1)<5 do i1:=' '+i1; i:=i+i1;
  789.   i:=i+'  '+f.date+'  '; i1:=cstr(f.owner); while length(i1)<3 do i1:=' '+i1;
  790.   i:=i+i1;
  791.   printacr(i,abort,next);
  792. end;
  793.  
  794. procedure browsefiles;
  795. var pl,n,nfl,cn:integer; f:ulfrec; i,i1:str; abort,next,list,done:boolean;
  796. begin
  797.   iscan(pl); nl; nl; helpl:='B';
  798.     print('('+uboards[culb].name+') - '+cstr(pl)+' files');
  799.     if pl<>0 then begin
  800.     nl; abort:=false; done:=false;
  801.     prompt('Start at? '); input(i,3); cn:=value(i); if cn=0 then cn:=1;
  802.     if i='Q' then cn:=0; if cn>pl then cn:=0;
  803.     if cn>0 then begin list:=true;
  804.       repeat
  805.         tleft;
  806.         if list then begin
  807.           if cn>pl then cn:=1;
  808.           nfl:=0;
  809.           print(' NN: filename.ext   blcks  mm/dd/yy  frm');
  810.           while (not hangup) and (nfl<10) and (not abort) and (cn<=pl) do begin
  811.             listf(cn,abort); cn:=cn+1; nfl:=nfl+1;
  812.           end;
  813.           list:=false;
  814.         end;
  815.         nl; prompt('Browse: (1-'+cstr(pl)+',^'+cstr(cn)+'),U,D,Q,L,? :');
  816.         input(i,3); n:=0;
  817.         if (i='') and (cn>pl) then i:='Q';
  818.         n:=value(i); if (n>0) and (n<=pl) then begin cn:=n; i:='D'; end;
  819.         if i='?' then begin print('U:pload     D:ownload');
  820.                             print('Q:uit       L:ist files'); end;
  821.         if i='Q' then done:=true;
  822.         if i='L' then list:=true;
  823.         if i='U' then begin close(ulff); iul; iscan(pl); end;
  824.         if i='D' then begin
  825.           if n=0 then begin print('Download -'); nl; prompt('Which number? ');
  826.             input(i1,3); n:=value(i1); end;
  827.           if (n>0) and (n<=pl) then dl1(n);
  828.         end;
  829.       until done or hangup;
  830.     end;
  831.   end;
  832.   close(ulff);
  833. end;
  834.  
  835. procedure pointdate;
  836. var i:str; n:integer;
  837. begin
  838.   nl; nl; nl; helpl:='P';
  839.   print('Enter limiting date for new files -');
  840.   print('Date is currently set to '+ldat);
  841.   print(' mm/dd/yy');
  842.   prompt(':'); input(i,8);
  843.   nl; nl;
  844.   n:=daynum(i);
  845.   if n=0 then
  846.     print('Illegal date.')
  847.   else
  848.     ldat:=i;
  849.   nl; print('Current limiting date is '+ldat);
  850. end;
  851.  
  852. procedure listboards;
  853. var b:integer; i:str; abort,next:boolean;
  854. begin
  855.   nl;nl; print('Directories available to you:'); nl; nl;
  856.   b:=1; abort:=false;
  857.   while (b<=maxulb) and (not abort) and (not hangup) do begin
  858.     if uboards[b].dsl<=thisuser.dsl then begin
  859.        i:=cstr(b);
  860.        if length(i)=1 then i:=' '+i;
  861.        i:=i+' : '+uboards[b].name;
  862.        printacr(i,abort,next);
  863.     end;
  864.     b:=b+1;
  865.   end;
  866.   nl;nl;
  867. end;
  868.  
  869. procedure mmkey(var i:str);
  870. var c:char;
  871. begin
  872.   repeat
  873.     repeat
  874.       getkey(c);
  875.       skey(c);
  876.     until (((c>=' ') and (c<chr(127))) or (c=chr(13))) or hangup;
  877.     c:=upcase(c);
  878.     outkey(c);
  879.     thisline:=thisline+c;
  880.     if (c='/') or (c='1') then begin
  881.       i:=c;
  882.       repeat
  883.         getkey(c);
  884.         skey(c);
  885.       until ((c>=' ')and(c<=chr(127))) or (c=chr(13)) or (c=chr(8)) or hangup;
  886.       c:=upcase(c);
  887.       if c<>chr(13) then begin outkey(c); thisline:=thisline+c; end;
  888.       if (c=chr(8)) or (c=chr(127)) then prompt(' '+c);
  889.       if c='/' then input(i,20) else if c<>chr(13) then i:=i+c;
  890.     end else i:=c;
  891.   until (c<>chr(8)) and (c<>chr(127)) or hangup;
  892.   nl;
  893. end;
  894.  
  895. procedure reqchat;
  896. begin
  897.   nl;nl; if (not sysop) or (rchat in thisuser.ac)
  898.   then begin
  899.     print('Sysop not available.');
  900.   end else begin
  901.     if not chatcall then begin
  902.       helpl:='C'; prompt('Reason: '); inputl(i,70);
  903.       if i<>'' then begin
  904.         sysoplog('Chat: '+i);
  905.         print('Chat call now on.');
  906.         sound(440); delay(500); nosound;
  907.         chatr:=i; chatcall:=true;
  908.       end else chatr:='';
  909.     end else
  910.       begin chatcall:=false; print('Chat call turned off.'); chatr:='';end;
  911.   end;
  912.   nl;nl; topscr;
  913. end;
  914.  
  915. procedure yourinfo;
  916. begin
  917.   nl; nl;
  918.   print('Your name : '+nam);
  919.   print('Your SL   : '+cstr(thisuser.sl));
  920.   print('Your DSL  : '+cstr(thisuser.dsl));
  921.   print('You D/L''d : '+cstr(thisuser.dk)+'K in '+cstr(thisuser.downloads)+' files');
  922.   print('You U/L''d : '+cstr(thisuser.uk)+'K in '+cstr(thisuser.uploads)+' files');
  923. end;
  924.  
  925. procedure ftmainmenu;
  926. var ii,i:str; int:integer;
  927. begin
  928.   dump; tleft; nl; nl;
  929.   print('T - '+tlef);
  930.   i:='('+cstr(culb)+')-('+uboards[culb].name+')  :';
  931.   prompt(i);
  932.   helpl:='T';
  933.   mmkey(i);
  934.   helpl:=#0;
  935.   if length(i)=1 then case i[1] of
  936.     '?':printfile('gfiles\dlmenu.msg');
  937.     'Q':doneft:=true;
  938.     'B':browsefiles;
  939.     'U':iul;
  940.     'D':idl;
  941.     'L':listfiles;
  942.     'S':search;
  943.     'F':searchd;
  944.     'C':reqchat;
  945.     'O':begin
  946.           nl;nl;prompt('Hangup?  Sure? '); helpl:='O';
  947.           if yn then begin
  948.             cls;
  949.             printfile('gfiles\logoff.msg');
  950.             hangup:=true;
  951.             hungup:=false;
  952.           end;
  953.         end;
  954.     '*':listboards;
  955.     'P':pointdate;
  956.     'N':nf;
  957.     'R':remove;
  958.     'M':if cs then move;
  959.     'V':lfii;
  960.     'Y':yourinfo;
  961.   end;
  962.   if i='/O' then hangup:=true;
  963.   if (i='SORT') and cs then sort;
  964.   if (i='REN') and cs then ren;
  965.   if (i='0') and cs then culb:=0;
  966.   int:=value(i); if (int>0) and (int<=maxulb) then
  967.     if thisuser.dsl>=uboards[int].dsl then
  968.       if (uboards[int].password='') or cs then culb:=int else begin
  969.         prompt('Password? '); input(i,10);
  970.         if i<>uboards[int].password then
  971.           print('Wrong.')
  972.         else
  973.           culb:=int;
  974.        end;
  975. end;
  976.  
  977. begin
  978.   iport; i1; doneft:=false;
  979.   while (not doneft) and (not hangup) do
  980.     ftmainmenu;
  981.   ret:=200;
  982.   return;
  983. end.